package com.bringway.p2p.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.bringway.framework.controller.JsonController;
import com.bringway.framework.util.RequestUtils;
import com.bringway.p2p.service.UserdzService;
import com.bringway.p2p.service.ZqzrlbService;



/**
 * 
 * @author zhai
 * @version 创建时间：2015年12月16日 上午9:34:42
 * @功能：债权收益界面
 */
@Controller
@RequestMapping("/userdz")
public class UserdzController extends JsonController{
	@Autowired
	UserdzService userdzService;
	
	/**
	 * 
	 * @param request 用户对账表查询
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("queryUserdzList")
	public ModelAndView queryTxList(HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		Integer page = RequestUtils.getIntParameter(request, "page");//新版本,传参
		Integer start = RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		if (null!=page) {//新版本,传参
			start=(page-1)*limit;
		}
		String gyh = RequestUtils.getStringParameter(request, "gyh");
		String sjhm = RequestUtils.getStringParameter(request, "sjhm");
		params.put("start", start);
		params.put("limit", limit);
		params.put("gyh", gyh);
		params.put("sjhm", sjhm);
		List<Map<String, Object>> list = userdzService.queryUserdz(params);
		int count = userdzService.getUserdzCount(params);
		result.put("data", list);	
		result.put("total", count);
		if (null!=page) {//新版本,传参
			int totalPage=count%limit==0?count/limit:count/limit+1;
			result.put("totalPage", totalPage);
		}
		serialize(request,response,result);
		return null;
	}
	
	
	@RequestMapping("queryAllInfo")
	public ModelAndView queryAllInfo(HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject result = new JSONObject();
		String username = RequestUtils.getStringParameter(request, "gyh");
		List<?> list = userdzService.queryAllJe(username);
		List<?> czje = userdzService.queryCZJE(username);
		Map<String, Object> txsxf = userdzService.queryTxSxf(username);
		Map<String, Object> dianjuan = userdzService.queryDianJuan(username);
		result.put("list", list);
		result.put("czje", czje);
		result.put("txsxf", txsxf);
		result.put("dianjuan", dianjuan);
		serialize(request, response, result);
		return null;
	}
}
